package com.gugee.tiktok.deploy.consumer.blogger.controller;


import com.gugee.tiktok.common.model.ai.blogger.FaceRecognition;
import com.gugee.tiktok.data.common.msg.BloggerMessage;
import com.gugee.tiktok.data.common.msg.CommentMessage;
import com.gugee.tiktok.data.common.msg.FansPortraitMessage;
import com.gugee.tiktok.data.common.msg.KeywordMessage;
import com.gugee.tiktok.data.consumer.blogger.core.ai.BloggerAiClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class NacosConfigControllerTest {

    @Autowired
    @Qualifier("kafkaTemplateBlogger")
    private KafkaTemplate<Long, BloggerMessage> kafkaTemplateBlogger;

    @Autowired
    @Qualifier("kafkaTemplateFansPortrait")
    private KafkaTemplate<Long, FansPortraitMessage> kafkaTemplateFansPortrait;

    @Autowired
    BloggerAiClient bloggerAiClient;

    @RequestMapping(path = "/send/blogger/{uid}/{times}")
    public void sendFoo(@PathVariable Long uid,@PathVariable Long times) {
        BloggerMessage bloggerMessage = new BloggerMessage();
            bloggerMessage.setUid(uid);
            this.kafkaTemplateBlogger.send("blogger_day", bloggerMessage.getId(), bloggerMessage);
            log.info("send uid={} success",uid);

    }

//    @Autowired
//    @Qualifier("kafkaTemplateHashtag")
//    private KafkaTemplate<Long, HashtagMessage> kafkaTemplateHashtag;
//
//    @RequestMapping(path = "/send/Hashtag/{hid}/{times}")
//    public void sendHashtagMessage(@PathVariable Long hid,@PathVariable Long times) {
//        HashtagMessage hashtagMessage = new HashtagMessage();
//        for(int i=0;i<times;i++) {
//            hashtagMessage.setHid(hid);
//            hashtagMessage.setId(hid+1);
//            this.kafkaTemplateHashtag.send("hashtag_day", hashtagMessage.getId(), hashtagMessage);
//        }
//    }

    @Autowired
    @Qualifier("kafkaTemplateComment")
    private KafkaTemplate<Long, CommentMessage> kafkaTemplateComment;
    @PostMapping(path = "/send/Comment")
    public void sendCommentMessage(@RequestBody CommentMessage commentMessage) {
            this.kafkaTemplateComment.send("comment_day", commentMessage.getId(), commentMessage);
    }

    @Autowired
    @Qualifier("kafkaTemplateKeyword")
    private KafkaTemplate<Long, KeywordMessage> kafkaTemplateKeyword;
    @PostMapping(path = "/send/Keyword")
    public void sendKeywordMessage(@RequestBody KeywordMessage keywordMessage) {
        this.kafkaTemplateKeyword.send("keyword_day", keywordMessage.getId(), keywordMessage);
    }

    @RequestMapping(path = "/send/fans/{uid}/{awemeId}")
    public void sendFansPortrait(@PathVariable Long uid,@PathVariable Long awemeId) {
        FansPortraitMessage fansPortraitMessage = new FansPortraitMessage();
        fansPortraitMessage.setId(awemeId);
        fansPortraitMessage.setUid(uid);
        fansPortraitMessage.setAwemeId(awemeId);
        this.kafkaTemplateFansPortrait.send("fansportrait_day", fansPortraitMessage.getId(), fansPortraitMessage);
        log.info("send awemeId={} success",awemeId);

    }
    @RequestMapping(path = "/send/ai/{uid}/{url}")
    public void callAi(@PathVariable Long uid,@PathVariable String url) {
        FaceRecognition faceRecognition = bloggerAiClient.getFaceRecognitionByPicUrl(uid,"https://www.baidu.com/img/flexible/logo/pc/result.png");
        log.info("send awemeId={} success",faceRecognition);

    }
}


